<?php
	error_reporting(0);
	$last_id = $_GET["last"];
	if($last_id=="") {
		$last_id = 0;
	}
	$useIp = $_SERVER["REMOTE_ADDR"];
	$ts = date("Y-m-d H:i:s");
	$con = mysql_connect("localhost","root","12347890");
	mysql_select_db("chat");
	if($_GET["cont"]) {
		$name = $_GET["named"];
		$msg = $_GET["cont"];
		$sql = "insert into chat(name,msg,ip,times) values('{$name}','{$msg}','{$useIp}', '{$ts}')";
		$res = mysql_query($sql);
	}
	header("Content-Type: text/xml");
	header("Cache-Control: no-cache, must-revalidate");
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
?><ppl>
<?php
	$sql = "select * from chat";
	//ini_set('error_log', 'error_log');
	//error_log($sql);
	$res = mysql_query($sql);
	while($row=mysql_fetch_array($res)) {
		$useName = $row["name"];
		$useMsg = $row["msg"];
		$useIp = $row["ip"];
		if($last_id < $row["id"]) {
			$last_id = $row["id"];
		}
		$xml = '<items>
		<name>'.$useName.'</name>
		<conts>'.$useMsg.'</conts>
		<ip>'.$useIp.'</ip>
	</items>
		'.$xml;
	}
	$xml = "	<num>{$last_id}</num>".$xml;
	echo $xml;
?>
</ppl>